<?php

namespace App\Http\Controllers\Home;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Cart;
use App\Http\Requests\CartRequest;
use App\Services\CartService;

class CartController extends Controller
{
    private $cartService;

    public function __construct(CartService $service) {
        $this->cartService = $service;
    }

    public function store(Request $request, CartService $cartService)
    {
    	$datas = $request->input();
    	$res = $cartService->createCart($datas);
    	return response()->json($res);
    }

    public function index(CartService $cartService)
    {
    	$carts = $cartService->getCarts();
    	return view('home.carts.index', ['datas' => $carts]);
    }

    public function destroy($id)
    {
        $cartService->removeCart($id);
    }
}
